package test.enba.encrypt.controller;

import com.enba.boot.encrypt.EncryptHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/encrypt")
public class EncryptController {

  @Autowired private EncryptHelper encryptHelper;

  /** AES加密 */
  @GetMapping("/performAesEncryption")
  public String symmetricEncrypt() throws Exception {
    String s = encryptHelper.performAesEncryption("123456789");
    System.out.println(s);
    return s;
  }

  /** AES解密 */
  @GetMapping("/performAesDecryption")
  public String symmetricDecrypt(@RequestParam String encryptedData) throws Exception {
    String s = encryptHelper.performAesDecryption(encryptedData);
    System.out.println(s);
    return s;
  }

  /** RSA加密 */
  @GetMapping("/performRsaEncryption")
  public String asymmetricEncrypt() throws Exception {
    String s = encryptHelper.performRsaEncryption("123456789");
    System.out.println(s);
    return s;
  }

  /** RSA解密 */
  @GetMapping("/performRsaDecryption")
  public String asymmetricDecrypt(@RequestParam String encryptedData) throws Exception {
    String s = encryptHelper.performRsaDecryption(encryptedData);
    System.out.println(s);
    return s;
  }
}
